package com.loong.system.controller.forehead;


import com.loong.common.mvc.BaseForeheadController;
import com.loong.common.redis.RedisTools;
import com.loong.common.rest.Result;
import com.loong.global.constant.RedisKey;
import com.loong.system.common.forehead.param.SystemConfigureForeheadQueryParam;
import com.loong.system.common.forehead.result.SystemConfigureForeheadResult;
import com.loong.system.common.forehead.result.SystemConfigureRedisForeheadResult;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.List;


@RestController
@RequestMapping("forehead/system/configure")
public class SystemConfigureForeheadController extends BaseForeheadController {


    /**
     * 根据位置code查询配置信息
     * @param param
     * @return
     */
    @PostMapping("getPicture")
    public Result getConfigure(@RequestBody SystemConfigureForeheadQueryParam param){
        List<SystemConfigureRedisForeheadResult> list = new ArrayList<>();
        List<String> positionCodes = param.getCodes();
        if(CollectionUtils.isEmpty(positionCodes))return handlerExecutor.execute(()->list);;
        positionCodes.forEach(code->{
                    List<SystemConfigureForeheadResult> itemList = RedisTools.valueOperations().getList(RedisKey.SYSTEM.CONFIGURE_POSITION_CODE + code, SystemConfigureForeheadResult.class);
                    SystemConfigureRedisForeheadResult itemResult = SystemConfigureRedisForeheadResult.builder().positionCode(code).results(itemList).build();
                    list.add(itemResult);
                }
        );
        return handlerExecutor.execute(()->list);

    }
}
